const http = require('http')
const fs = require('fs')
const path = require('path')
const { error } = require('console')

const server = http.createServer()

server.on('request', (req, resp) => {
    const url = req.url

    console.log('请求url:' + url)

    // url == 'html'
    // console.log('请求url修改:' + url)



    const fpath = path.join(__dirname, url)
    console.log('读取文件路径:' + fpath)

    // if(url == '/favicon.ico'){
    //     resp.end('')
    // }

    fs.readFile(fpath, 'utf8', (error, dataStr) => {
        if(error) {
            console.log(error)
            resp.end('404 Not Found.')
        }
        console.log(dataStr)
        resp.end(dataStr)
    })


    if(url == '/clock.html') {
        // const fpath = path.join(__dirname, '../tesFile/clock/clock.html')
        resp.end()
    }

})


server.listen('80', () => {
    console.log('服务器已启动...http://127.0.0.1')
})